/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package icontrole.exp_one;

import java.text.DecimalFormat;
import java.util.HashMap;
import org.jfree.data.xy.XYSeries;

/**
 *
 * @author Amon
 */
public class Util {

    HashMap<Integer, Double> _hasmap;

    public HashMap<Integer, Double> getHasmap() {
        return _hasmap;
    }

    public void setHasmap(HashMap<Integer, Double> _hasmap) {
        this._hasmap = _hasmap;
    }

    public Util() {
        this._hasmap = new HashMap<Integer, Double>();
        this.LoadHash();
    }

    private void LoadHash() {
        Double value = 1.0;
        for (int i = 0; i < 11; i++) {
            this._hasmap.put(i, value);
            value += 0.2;
        }
    }

    public static String ShowSobreSinal(XYSeries signal, Double nivel) {
        Double value = 0.0;
        double signalMax = signal.getMaxY();
        if (signalMax > nivel) {
            value = (signalMax - nivel) / nivel;
        }
        return enxuga(value * 100).toString() + "%";
    }

    public static String ShowTempoDePico(XYSeries _xytank_I, double nivel_) {
        double signalMax = _xytank_I.getMaxY();
        int count = _xytank_I.getItems().size();
        Double tps = 0.0;
        for (int i = 0; i < count; i++) {
            Double y = (Double) _xytank_I.getY(i);
            if (y == signalMax) {
                tps = (Double)_xytank_I.getX(i);
            }
        }
        return null;//enxuga(tps).toString();
    }

    public static Double enxuga(double numero) {
        DecimalFormat format = new DecimalFormat();
        format.setMinimumFractionDigits(2);
        format.setMaximumFractionDigits(2);
        String form = format.format(numero);
        Double db = Double.parseDouble(form.replace(",", "."));
        return db;
    }
    public static Double Parse(String value){
        return enxuga( Double.parseDouble(value));
    }
}
